package com.lagou.edu.service.impl;

import com.lagou.edu.anno.Autowired;
import com.lagou.edu.anno.Service;
import com.lagou.edu.anno.Transaction;
import com.lagou.edu.dao.AccountDao;
import com.lagou.edu.pojo.Account;
import com.lagou.edu.service.TestService;
import com.lagou.edu.service.TransferService;

/**
 * @author 应癫
 */
@Transaction
@Service(value = "transferService", lazyInit = true)
public class TransferServiceImpl implements TransferService {

    @Autowired(value = "jdbcAccountDao")
    private AccountDao accountDao;

    @Autowired
    private TestService testService;

    @Override
    public void print() {
        System.out.println("TransferServiceImpl-print");
    }

    @Override
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {
        testService.testPrint();
        Account from = accountDao.queryAccountByCardNo(fromCardNo);
        Account to = accountDao.queryAccountByCardNo(toCardNo);

        from.setMoney(from.getMoney()-money);
        to.setMoney(to.getMoney()+money);

        accountDao.updateAccountByCardNo(to);
        System.out.println(1 / (money % 5));
        accountDao.updateAccountByCardNo(from);
    }
}
